//TODO:这里需要修改一个排名数据的接口地址
var gl_HOST = "https://localhost/";
var gl_iJSON = gl_HOST + 'mobile/index.php?';

var business = {

    QueryString: function (val) {
        const uri = window.location.search;
        const re = new RegExp("" + val + "=([^&?]*)", "ig");
        return ((uri.match(re)) ? (uri.match(re)[0].substr(val.length + 1)) : null);
    },
    getJsonDatas: function (name, param, callback, callback_err) {
        var data = {};
        var key = $api.getStorage('session_key');
        if (key == undefined) {
            key = business.QueryString('key');
        }
        var bi = businessNames[name];

        if (bi.method == 'post') {
            if (param.key != undefined) {
                param.key = key;
            }
            data = { values: param };
        }
        var url = bi.url.replace(/\{[\w]*?\}/g, function (w) {
            w = (w.replace('{', '')).replace('}', '');
            if (w == 'key') {
                return key;
            }
            if (param[w] != undefined)
                return param[w];
            else
                return '';
        });
        url = gl_iJSON + url;
        url = url + '&ver=' + api.systemType + '_' + api.appVersion;

        api.ajax({
            url: url,
            method: bi.method,
            cache: 'false',
            timeout: 30,
            dataType: 'json',
            data: data,
            //returnAll:true
        }, function (ret, err) {
            console.log('business.getJsonDatas.url:' + url);
            //console.log('business.getJsonDatas.POST:'+JSON.stringify(param));
            //console.log('business.getJsonDatas:ret='+JSON.stringify(ret))
            if (ret) {
                if (typeof callback === "function") {
                    callback(ret);
                } else {
                    return ret;
                }
            }
            else {
                if (typeof callback_err === 'function') {
                    callback_err(false);
                    return;
                }
                api.confirm({
                    title: '提示',
                    msg: '服务器繁忙，请稍候...',
                    buttons: ['立刻重试', '返回']
                }, function (ret, err) {
                    if (ret.buttonIndex == 1) {
                        business.getJsonDatas(name, param, callback);
                    }
                });
            }
        });
    }

};

